package com.hitqz.robot.camera.type;

import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

/**
 * 云台控制类型
 */
public enum PtzCtrlTypeEnum {

    LIGHT(2, 66, 0x00090002,"补光灯控制"),//没测试过,原来用的透传方式
    WIPER(3, 14, 0x00090001,"雨刷控制"),//没测试过,原来用的透传方式

    ZOOM_IN(11, 4, 0x00200000,"倍数放大"),
    ZOOM_OUT(12, 5, 0x00400000,"倍数缩小"),
    FOCUS_NEAR(13, 6, 0x00800000,"焦点前调"),
    FOCUS_FAR(14, 7, 0x01000000,"焦点后调"),
    IRIS_OPEN(15, 8, 0x02000000,"光圈扩大"),
    IRIS_CLOSE(16, 9, 0x04000000,"光圈缩小"),

    TILT_UP(21, 0, 0x0008001F,"上"),
    TILT_DOWN(22, 1, 0x0010001F,"下"),
    PAN_LEFT(23, 2, 0x00041F00,"左"),
    PAN_RIGHT(24, 3, 0x00021F00,"右"),
    UP_LEFT(25, 32, 0x000C1F1F,"左上"),
    UP_RIGHT(26, 33, 0x000A1F1F,"右上"),
    DOWN_LEFT(27, 34, 0x00141F1F,"左下"),
    DOWN_RIGHT(28, 35, 0x00121F1F,"右下");
    //海康
    private final int hkCmd;
    //大华
    private final int dhCmd;
    //pelcod
    private final int pelcodCmd;

    private final String desc;

    PtzCtrlTypeEnum(Integer hkCmd, Integer dhCmd,Integer pelcodCmd, String desc) {
        this.hkCmd = hkCmd;
        this.dhCmd = dhCmd;
        this.pelcodCmd = pelcodCmd;
        this.desc = desc;
    }

    public Integer getHkCmd() {
        return hkCmd;
    }

    public Integer getDhCmd() {
        return dhCmd;
    }

    public Integer getPelcodCmd() {
        return pelcodCmd;
    }

    public Integer getByBrand(String brand){
        brand = Optional.ofNullable(brand).orElse("HK").toUpperCase(Locale.ROOT);
        if (Objects.equals("HK", brand)){
            return hkCmd;
        }else if (Objects.equals("DH",brand)){
            return dhCmd;
        }else {
            return pelcodCmd;
        }
    }

    public static PtzCtrlTypeEnum fromHkCmd(Integer cmd) {
        for (PtzCtrlTypeEnum value : PtzCtrlTypeEnum.values()) {
            if (value.getHkCmd().equals(cmd)) {
                return value;
            }
        }
        return null;
    }

    public static PtzCtrlTypeEnum fromDHCmd(Integer cmd) {
        for (PtzCtrlTypeEnum value : PtzCtrlTypeEnum.values()) {
            if (value.getDhCmd().equals(cmd)) {
                return value;
            }
        }
        return null;
    }

    public static PtzCtrlTypeEnum fromPelcodCmd(Integer cmd) {
        for (PtzCtrlTypeEnum value : PtzCtrlTypeEnum.values()) {
            if (value.getPelcodCmd().equals(cmd)) {
                return value;
            }
        }
        return null;
    }

}
